package ua.com.infopulse.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import ua.com.infopulse.R;
import ua.com.infopulse.db.DBGetter;
import ua.com.infopulse.db.DataTrackManager;
import ua.com.infopulse.spesial_data.StringIntCouple;

/**
 * @author Andrew.Nazymko
 */
public class PointListAdapter extends BaseAdapter {
    private String TAG = PointListAdapter.this.getClass().getSimpleName();
    List<StringIntCouple> item_list;
    private Context context;

    public PointListAdapter(List<StringIntCouple> item_list, Context context) {
        this.context = context;
        this.item_list = item_list;
    }

    /**
     * does not work yet
     * @serialData
     */
    public void refresh() {
        DataTrackManager manager = DBGetter.getDTM();
        item_list = manager.getCheckInList();
        notifyDataSetChanged();              //update not working
        notifyDataSetInvalidated();
    }

    public void bindView(View view, StringIntCouple couple) {
        int id = couple.getIntPair();
        view.setTag(id);
        TextView checkInDesc = (TextView) view.findViewById(R.id.check_in_text_message);
        String description = couple.getStringPair();
        checkInDesc.setText(description);
        view.setEnabled(true);
    }

    @Override
    public int getCount() {
        return item_list.size();
    }

    @Override
    public Object getItem(int index) {
        return item_list.get(index);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }


    @Override
    public boolean areAllItemsEnabled() {
        return true;
    }


    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null) {
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.check_in_element, viewGroup, false);
        }
        bindView(view, item_list.get(position));
        return view;
    }
}
